/*
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2021-10-21 16:48:53
 * @LastEditors: sueRimn
 * @LastEditTime: 2021-10-21 17:13:24
 */
// 根据角色动态生成路由
import { MockMethod } from 'vite-plugin-mock';

const permissionRouter = {
  path: '/permission',
  name: 'permission',
  redirect: '/permission/page',
  meta: {
    title: 'message.permission',
    icon: 'el-icon-lollipop',
    showLink: true,
    rank: 3
  },
  children: [
    {
      path: '/permission/page',
      name: 'permissionPage',
      meta: {
        title: 'message.permissionPage',
        showLink: true
      }
    },
    {
      path: '/permission/button',
      name: 'permissionButton',
      meta: {
        title: 'message.permissionButton',
        showLink: true,
        authority: []
      }
    }
  ]
};

const permissionRouter1 = {
  path: '/permission',
  name: 'permission',
  redirect: '/permission/page',
  meta: {
    title: 'message.permission',
    icon: 'el-icon-lollipop',
    showLink: true,
    rank: 3
  },
  children: [
    {
      path: '/permission/page',
      name: 'permissionPage',
      meta: {
        title: 'message.permissionPage',
        showLink: true
      }
    },
    {
      path: '/permission/button',
      name: 'permissionButton',
      meta: {
        title: 'message.permissionButton11',
        showLink: true,
        authority: []
      }
    }
  ]
};
// 添加不同按钮权限到/permission/button页面中
function setDifAuthority(authority, routes) {
  routes.children[1].meta.authority = [authority];
  return routes;
}

export default [
  {
    url: '/getAsyncRoutes',
    method: 'get',
    response: ({ query }) => {
      if (query.name === 'admin') {
        return {
          code: 0,
          info: [setDifAuthority('v-admin', permissionRouter)]
        };
      } else {
        return {
          code: 0,
          info: [setDifAuthority('v-test', permissionRouter1)]
        };
      }
    }
  }
] as MockMethod[];
